/**
 * 
 */
package com.cipe.cmrs.controllers;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.cipe.cmrs.model.Cipeprojecttype;
import com.cipe.cmrs.service.CipeprojecttypeService;

/**
 * @author Incepio
 *
 */
@Controller
public class CipeprojecttypeController extends BaseController {

	/**
	 * 
	 */
	private static final long		serialVersionUID	= -3823562098119817733L;
	@Autowired
	private CipeprojecttypeService	cipeprojecttypeService;

	@RequestMapping("/secure/showAddCipeprojecttype.do")
	public String showAddCipeprojecttype(Model model) {
		model.addAttribute("cipeprojecttype", new Cipeprojecttype());
		return "editCipeprojecttype";
	}

	@RequestMapping("/secure/showEditCipeprojecttype.do")
	public String showEditCipeprojecttype(@RequestParam Integer id, Model model) {
		model.addAttribute("cipeprojecttype", cipeprojecttypeService.findById(id));
		return "editCipeprojecttype";
	}

	@RequestMapping("/secure/saveCipeprojecttype.do")
	public String SaveCipeprojecttype(@ModelAttribute("cipeprojecttype") Cipeprojecttype cipeprojecttype, BindingResult result, Model model, HttpServletRequest request) {
		try {
			cipeprojecttype = cipeprojecttypeService.saveCipeprojecttype(cipeprojecttype, getUserId(request));
			saveMessage(request, getText("editCipeprojecttype.message.success"));
		} catch (Exception e) {
			logger.error(getText("error.transaction"), e);
			saveError(request, getText("error.transaction"));
		}
		model.addAttribute("cipeprojecttype", cipeprojecttype);
		return "editCipeprojecttype";
	}

	@RequestMapping("/secure/showCipeprojecttypeList.do")
	public String showCipeprojecttypeList(Model model) {
		model.addAttribute("cipeprojecttypes", cipeprojecttypeService.findAll());
		return "cipeprojecttypeList";
	}
}
